import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'

Vue.use(VueRouter)

  const routes = [
    {
      path: '/',
      name: 'Login',
      component: Login
    },
    {
      path: '/Home',
      name: 'Home',
      component: Home
    },
    
]
const router = new VueRouter({
  routes,
  // mode:'history'
})
router.beforeEach(async(to, from, next) => {
  const loginToken = localStorage.getItem("LoginToken");
  const { token } = to.query
  console.log(to.query,'22222222222');
  console.log(token,'33333333333');
  if (token) {
      localStorage.setItem("LoginToken", token);
      next({
          name: to.name
      });
      return
  }
  // if (to.name != "login") {
  //     await store.dispatch('PortalManagement/SET_PERMISSION_CODE');
  //     //获取到菜单的权限列表-vuex的获取
  //     let allAtth = store.state.PortalManagement.PermissionCode;
  //     allAtth.push("important_grzx");
  //     // console.log(to.meta.code, "to.meta.code");
  //     if (new Set(allAtth).has(to.meta.code)) {
  //         next()
  //         console.log("能访问");
  //     } else {
  //         next({ name: login })
  //         console.log("不能访问");
  //     }
  // }
  next()
})


export default router
